const host = window.location.hostname;
//接收前端要发送的消息
let toBeSend = "132";
//发送消息按钮
let sendBtn;
let ws = new WebSocket(`ws://${host}:8080/AVR/websocket`);

ws.onopen = function() {
    console.log('WebSocket 连接已经建立。');
    if(sendBtn.click()){
        ws.send(toBeSend);
    }
};

ws.onmessage = function(event) {
    console.log('收到服务器消息：', event.data);
};

ws.onerror = function(event) {
    console.error('WebSocket 连接出现错误：', event);
};

ws.onclose = function() {
    console.log('WebSocket 连接已经关闭。');
};